package com.GamersCom.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GameRateDAO
{
	protected QueryMgr qm = new QueryMgr();
	
	public void insert(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public List<GameRate> getAll(String query) throws SQLException
	{
		ResultSet rs = qm.fetchList(query);
		List<GameRate> list = new ArrayList<GameRate>();
		
		if ( ! rs.isBeforeFirst())
		{
			return null;
		}
		
		while ( rs.next() ) 
		{
			GameRate gameRate = new GameRate();
			gameRate.setId(rs.getInt("id"));
			gameRate.setScore(rs.getInt("score"));
			gameRate.setGameId(rs.getInt("game_id"));
			gameRate.setUserId(rs.getInt("user_id"));
			
			list.add(gameRate);
		}
		
		return list;
	}
	
	public List<GameRate> getAll(String query, List paramList) throws SQLException 
	{
		ResultSet rs = qm.fetchList(query,paramList);
		List<GameRate> list = new ArrayList<GameRate>();
		
		if ( ! rs.isBeforeFirst())
		{
			return null;
		}
		
		while ( rs.next() ) 
		{
			GameRate gameRate = new GameRate();
			gameRate.setId(rs.getInt("id"));
			gameRate.setScore(rs.getInt("score"));
			gameRate.setGameId(rs.getInt("game_id"));
			gameRate.setUserId(rs.getInt("user_id"));
			
			list.add(gameRate);
		}
		
		return list;
	}
}
